package com.zb.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjNetworkEmpAddress;
import com.zb.mapper.ZjNetworkEmpAddressMapper;
import com.zb.result.PageUtil;
import com.zb.service.ZjNetworkEmpAddressService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 网点人员地址表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-11-20
 */
@Service
public class ZjNetworkEmpAddressServiceImpl extends ServiceImpl<ZjNetworkEmpAddressMapper, ZjNetworkEmpAddress> implements ZjNetworkEmpAddressService {
    @Resource
    private ZjNetworkEmpAddressMapper networkEmpAddressMapper;


    // 根据服务人员ID获取默认地址
    @Override
    public ZjNetworkEmpAddress getDefaultAddressByNetworkEmpId(Long networkEmpId) {
        return networkEmpAddressMapper.getDefaultAddressByNetworkEmpId(networkEmpId);
    }

    // 根据服务人员ID获取默认地址
    @Override
    public List<ZjNetworkEmpAddress> getDefaultAddressByNetworkEmpIds(List<Long> networkEmpIds) {
        if (CollectionUtil.isEmpty(networkEmpIds)) {
            return new ArrayList<>();
        }
        QueryWrapper<ZjNetworkEmpAddress> wrapper = new QueryWrapper<>();
        wrapper.select("network_emp_id", "province", "city", "area", "town", "address")
                .in("network_emp_id", networkEmpIds)
                .eq("is_default_address", true);
        return this.list(wrapper);
    }

}
